<template>
  <div>
    <div class="roof">
      <van-icon
        name="arrow-left"
        @click="fh"
        style="
          float: left;
          font-size: 20px;
          margin-left: 10px;
          margin-top: 10px;
        "
      />
      <h4>创建新地址</h4>
    </div>

    <div class="major">
      <div class="main">
        <van-address-edit
          :area-list="areaList"
          show-set-default
          show-search-result
          :search-result="searchResult"
          :area-columns-placeholder="['请选择', '请选择', '请选择']"
          @save="onSave"
          @change-detail="onChangeDetail"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { areaList } from "@vant/area-data";
import { Toast } from "vant";
import { address } from "../../api/address";
export default {
  data() {
    return {
      areaList,
      searchResult: [],
      isDefault: 0,
    };
  },
  methods: {
    fh() {
      this.$router.go(-1);
    },
    onSave(val) {
      if (val.isDefault == false) {
        this.isDefault = 0;
      } else if (val.isDefault == true) {
        this.isDefault = 1;
        console.log(234);
      }
      // Toast("save");
      console.log(val);
      address({
        name: val.name,
        tel: val.tel,
        area: val.province + val.city + val.county,
        address: val.addressDetail,
        isDefault: this.isDefault,
        uid: 1,
      }).then((res) => {
        console.log(res);
      });
    },
    onDelete() {
      console.log(245);
      Toast("delete");
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: "黄龙万科中心",
            address: "杭州市西湖区",
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
  },
};
</script>

<style scoped>
.roof {
  height: 40px;
  background-color: rgb(255, 255, 255);
  /* margin-top: 10px; */
  line-height: 40px;
  padding-top: 8px;
  box-sizing: border-box;
}
.roof h4 {
  text-align: center;
  margin: 0;
  margin-right: 20px;
}

.major {
  height: 788px;
  background-color: rgb(247, 247, 247);
}
.main {
  width: 350px;
  line-height: 40px;
  font-size: 14px;
  margin: 0px auto;
  margin-top: 10px;
  border-radius: 10px;
  overflow: hidden;
  border: 0;
  padding-top: 10px;
}
</style>